#ifndef _HLC_FP_HPP_
#define _HLC_FP_HPP_

#include <string>
#include "CHIP_PIN.hpp"
#include "CHIP_UART.hpp"

extern "C"
{
#include <rtthread.h>
#include <rtdevice.h>
#include <stdint.h>

}

typedef enum
{
    hlc_fp_device_type_FPM383,

}hlc_fp_device_type;

typedef enum
{
    hlc_fp_status_ok,
    hlc_fp_status_fail,
    hlc_fp_status_checksum_error,
    hlc_fp_status_system_busy,
    hlc_fp_status_system_error
} hlc_fp_status;


class HLC_FP
{
private:
    uint8_t link_layer_frame_head[8];
    uint8_t app_layer_password[4];

    CHIP_INPUT_PIN* touch_pin;
    CHIP_OUTPUT_PIN* power_pin;
    CHIP_UART*uart;

    hlc_fp_device_type device_type;
    hlc_fp_status init_flag;

    rt_mutex_t serial_lock;//多线程调用成员函数时，务必用该锁

    void _hlc_fp_send_message(uint32_t data_len,uint8_t* data_buff);
    chip_uart_message* _hlc_fp_receive_message(uint32_t timeout);//使用后需要delete返回值
    uint8_t _hlc_fp_protocol_count_checksum(uint32_t data_len,uint8_t * data_buff);

    hlc_fp_status _hlc_fp_check_response(chip_uart_message* back_msg);
public:
    HLC_FP(CHIP_UART* uart,CHIP_OUTPUT_PIN* power_pin,CHIP_INPUT_PIN* touch_pin,hlc_fp_device_type device_type,uint32_t fp_pwd);
    hlc_fp_status HLC_FP_init();
    void HLC_FP_waiting_for_good();

    hlc_fp_status HLC_FP_send_CMD(uint8_t CMD1,uint8_t CMD2,uint32_t app_data_len,uint8_t* app_data_buff);

    hlc_fp_status HLC_FP_auto_reg_fp();
    hlc_fp_status HLC_FP_stop_reg_or_match_fp();
    hlc_fp_status HLC_FP_auto_update_fp(uint8_t ID_H,uint8_t ID_L);

    hlc_fp_status HLC_FP_delete_all_fp();

    hlc_fp_status HLC_FP_check_fp_on_pos();
    hlc_fp_status HLC_FP_match_fp();

    hlc_fp_status HLC_FP_sleep();//383F有重置touch pin电平功能

    hlc_fp_status HLC_FP_reset();

    hlc_fp_status HLC_FP_check_alive();

    //color 0x01绿 0x02红 0x03黄 0x04蓝 0x05紫 0x06淡蓝 0x07白
    hlc_fp_status HLC_FP_led_control(uint8_t mode,uint8_t color,uint8_t pra1,uint8_t pra2,uint8_t pra3);

    hlc_fp_status HLC_FP_read_init_status();

    void HLC_FP_take_mutex();
    void HLC_FP_release_mutex();


};




#endif /* _HLC_FP_HPP_ */
